package com.banquetmanagementsystem.controller;

import com.banquetmanagementsystem.common.Utils.CaptchaUtil;
import com.banquetmanagementsystem.common.constant.MessageConstant;
import com.banquetmanagementsystem.common.response.Result;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 86176
 */
@RestController
public class CaptchaImageController {
    @Resource
    private CaptchaUtil captchaUtil;
    @GetMapping("/CaptchaImage")
    public Result<?> getCaptchaImage(HttpServletRequest request) {
        String code = captchaUtil.getCode();
        HttpSession session = request.getSession(true);
        session.setMaxInactiveInterval(60*3);
        session.setAttribute("captcha", code);
        return Result.success("data:image/png;base64,"+captchaUtil.getBase64(code), MessageConstant.OPERATION_SUCCESSFUL)  ;
    }
}
